#/bin/bash

directories=("/dev/sgx_enclave" "/dev/sgx_provision")


run_with_sgx(){
    docker run \
        --name sgxtee \
        --device=/dev/sgx_enclave:/dev/sgx/enclave\
        --device=/dev/sgx_provision:/dev/sgx/provision\
        -v aesmd-socket:/var/run/aesmd \
        -v /root/docker-calculation-center/rongan-pgateway/public/tee/conf/run:/usr/local/rongan/tee/conf \
        -v /root/docker-calculation-center/rongan-pgateway/public/tee/conf/sgx/default.json:/opt/intel/sgx-dcap-pccs/config/default.json \
        -v /root/docker-calculation-center/rongan-pgateway/public/tee/conf/sgx/sgx_default_qcnl.conf:/etc/sgx_default_qcnl.conf \
        -v /root/docker-calculation-center/rongan-pgateway/public/tee/conf/sgx/network_setting.conf:/opt/intel/sgx-pck-id-retrieval-tool/network_setting.conf \
        -v /root/docker-calculation-center/rongan-pgateway/public/tee/packages:/usr/local/rongan/tee/packages \
        -v /root/docker-calculation-center/rongan-pgateway/public/tee/service:/usr/local/rongan/tee/service \
        --net rongan-network \
        -itd sgx_tee
}

run_without_sgx(){
    docker run \
        --name sgxtee \
        -p 33333:33333 \
        -v aesmd-socket:/var/run/aesmd \
        -v /root/docker-calculation-center/rongan-pgateway/public/tee/conf/run:/usr/local/rongan/tee/conf \
        -v /root/docker-calculation-center/rongan-pgateway/public/tee/conf/sgx/default.json:/opt/intel/sgx-dcap-pccs/config/default.json \
        -v /root/docker-calculation-center/rongan-pgateway/public/tee/conf/sgx/sgx_default_qcnl.conf:/etc/sgx_default_qcnl.conf \
        -v /root/docker-calculation-center/rongan-pgateway/public/tee/conf/sgx/network_setting.conf:/opt/intel/sgx-pck-id-retrieval-tool/network_setting.conf \
        -v /root/docker-calculation-center/rongan-pgateway/public/tee/packages:/usr/local/rongan/tee/packages \
        -v /root/docker-calculation-center/rongan-pgateway/public/tee/service:/usr/local/rongan/tee/service \
        --net rongan-network \
        -itd sgx_tee
}

result=$(cat /proc/cpuinfo | grep sgx)
#echo "$result"

if [[ $result ]]; then
    echo "===== TEE环境启动 ====="
    run_with_sgx
else
    echo "===== 非TEE环境启动 ====="
    run_without_sgx
fi

#docker ps

#docker exec -it sgxtee /bin/bash
